import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_widgets/app_bar_widget.dart';
import 'package:basic_widgets/text_widget.dart';
import 'model/schedules_data_list.dart';
import 'service_manager_controller.dart';
class ServiceManagerPage extends GetView<ServiceManagerController> {
  const ServiceManagerPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: backAppbar(title: "服务管理"),
      body: SingleChildScrollView(
        physics: AlwaysScrollableScrollPhysics(),
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: ScreenHelper.width(15)),
          child: Column(
            children: [buildListItem()],
          ),
        ),
      ),
    );
  }

  Widget buildListItem() {
    return GetBuilder<ServiceManagerController>(
      id: 'scheduleList',
      builder: (controller) => controller.scheduListData == null ||
              controller.scheduListData.length == 0
          ? Align(
              alignment: Alignment.topCenter,
              child: EmptyBox(title: "暂无服务"),
            )
          : ListView.builder(
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemBuilder: (context, index) {
                SchedulesData itemData = controller.scheduListData[index];
                return GestureDetector(
                  onTap: () => controller.navToDetail(itemData),
                  child: listItem(
                      pName: itemData.patientname ?? '',
                      pIDCard: itemData.idcardno ?? '',
                      pAge: itemData.patientage ?? 0,
                      server: itemData.packagename ?? '',
                      status: itemData.servicestatus ?? '1',
                      teamName: itemData.teamname ?? ''),
                );
              },
              itemCount: controller.scheduListData.length),
    );
  }

  // listViewItem
  Widget listItem(
      {required String pName,
      required double pAge,
      required String pIDCard,
      required String teamName,
      required String server,
      required String status}) {
    return Card(
      elevation: 0,
      child: Padding(
        padding: const EdgeInsets.all(6.0),
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text(
                  "${pName}",
                  style: TextStyle(
                      color: AppTheme.dartTextColor,
                      fontSize: ScreenHelper.sp(16)),
                ),
                Container(
                  margin:
                      EdgeInsets.symmetric(horizontal: ScreenHelper.width(10)),
                  child: Text(
                    "${pAge.toInt()}岁",
                    style: TextStyle(
                        color: AppTheme.seconddarkWeakTextColor,
                        fontSize: ScreenHelper.sp(14)),
                  ),
                ),
                Image.asset(
                  'assets/mine/icon_sex_male.png',
                  width: ScreenHelper.width(14),
                  height: ScreenHelper.width(14),
                ),
                Expanded(
                    child: Text(
                  status == '1' ? '待服务' : "待服务",
                  textAlign: TextAlign.right,
                  style: TextStyle(
                      color: AppTheme.redtextColor,
                      fontSize: ScreenHelper.sp(14)),
                ))
              ],
            ),
            textItemWidget(attrName: '身份证号', value: '${pIDCard}'),
            textItemWidget(attrName: '签约团队', value: '${teamName}'),
            textItemWidget(attrName: '服务包', value: '${server}'),
          ],
        ),
      ),
    );
  }
}
